{extend name="sitehome@style/base"/}
{block name="resources"}
<style>
    .layui-tab .layui-tab-title li {
        border: 1px solid #e5e5e5;
        border-right: none;
        height: 36px;
        line-height: 36px;
    }

    .shop-title {
        color: #000;
    }

    .red-bar {
        width: 100%;
        height: 2px;
        background: #e8e8e8;
        margin-top: 15px;
        margin-bottom: 8px;
    }

    .reply {
        margin-left: 10px;
    }
</style>
{/block}
{block name="main"}
<div class="nc-table-box">
    <table id="commentList" lay-filter="comment" class="layui-table"></table>
</div>

<script type="text/html" id="report">
    <div>
        <div class="shop-title">{{d.info_array.title}}</div>
        <div class="red-bar"></div>
        <div class="reply">
            <div>内容：{{ d.report_explain}}</div>
            {{# if(d.refuse_reason != ''){ }}
            <span>拒绝理由：{{ d.refuse_reason}}</span><br>
            {{# } }}
        </div>
    </div>
</script>

<!-- 举报人 -->
<script type="text/html" id="username">
    <span>{{ d.username }}</span>
</script>

<!--时间-->
<script type="text/html" id="time">
    <div>{{nc.time_to_date(d.create_time)}}</div>
    {{# if(d.state_time != 0){}}
    <div>{{nc.time_to_date(d.state_time)}}</div>
    {{# }else{ }}
    <div>--</div>
    {{# } }}
</script>

<!-- 状态 -->
<script type="text/html" id="state">
    {{# if(d.state == 0){ }}
    <span>待审核</span>
    {{# }else if(d.state == 1){ }}
    <span>已审核</span>
    {{# }else if(d.state == -1){ }}
    <span>已拒绝</span>
    {{# } }}
</script>
<script type="text/html" id="operation">
    {{# if(d.state == 0){ }}
    <a class="default" lay-event="changeState">审核</a>
    {{# }}}
    <a class="default" lay-event="del">删除</a>
</script>

{/block}
{block name="script"}
<script type="text/javascript">
    var table = new Table({
        elem: '#commentList',
        filter: "comment",
        url: nc.url("sns://sitehome/manage/reportlist", {}),
        page: {
            layout: ['count', 'limit', 'prev', 'page', 'next'],
            limit: 10,
            curr: 1
        },
        cols: [
            [{
                    type: 'checkbox',
                    unresize: 'true'
                },
                {
                    toolbar: '#report',
                    width: '30%',
                    title: '信息',
                    align: 'left',
                }, {
                    width: '10%',
                    title: '举报人',
                    toolbar: '#username',
                    align: 'center',
                    unresize: 'true'
                },
                {
                    field: 'contact',
                    width: '15%',
                    title: '联系方式',
                    align: 'center',
                    unresize: 'true'
                },
                {
                    width: '20%',
                    title: '举报/审核时间',
                    toolbar: '#time',
                    align: 'center',
                    unresize: 'true'
                }, {
                    width: '10%',
                    title: '状态',
                    toolbar: '#state',
                    align: 'center',
                    unresize: 'true'
                }, {
                    title: '操作',
                    width: '10%',
                    toolbar: '#operation',
                    align: 'center',
                    unresize: 'true'
                }
            ]
        ]
    });

    //监听工具条
    table.tool(function (obj) {
        var report_id = obj.data.report_id;
        switch (obj.event) {
            case "changeState":
                var state;
                layer.open({
                    btn: ['同意', '拒绝'],
                    title: '如何处理此条举报信息',
                    btnAlign: 'c',
                    btn1: function (index, layero) {
                        changeState(report_id, 1);
                        layer.close(index);
                    },
                    btn2: function (index, layero) {
                        layer.prompt({
                            formType: 2,
                            value: '',
                            title: '您的拒绝理由为:',
                            area: ['300px', '200px'] //自定义文本域宽高
                        }, function (value, index, elem) {
                            changeState(report_id, -1, value);
                            layer.close(index);
                        })
                    }


                });
                break;
            case "del":
                delReport(report_id);
                break;
        }
    });

    // 改变举报状态值
    function changeState(report_id, state, refuse_reason = '') {
        console.log(report_id);
        $.ajax({
            url: nc.url('sns://sitehome/manage/reviewReport'),
            data: {
                'state': state,
                'report_id': report_id,
                'refuse_reason': refuse_reason
            },
            type: "GET",
            success: function (res) {
                if (res.code == 0) {
                    console.log(res);
                    var page_index = $('.layui-laypage-em').next().html();
                    table.reload('commentList', {
                        where: {},
                        page: {
                            curr: page_index
                        }
                    })
                }

            }
        })
    }
    // 删除举报
    function delReport(report_id) {
        layer.confirm('确定删除吗?', {
            btn: ['确定', '取消']
        }, function () {
            layer.closeAll('dialog');
            $.ajax({
                url: nc.url('sns://sitehome/manage/delReport'),
                data: {
                    'report_id': report_id
                },
                type: "GET",
                success: function (res) {
                    if (res.code == 0) {
                        var page_index = $('.layui-laypage-em').next().html();
                        table.reload('commentList', {
                            where: {},
                            page: {
                                curr: page_index
                            }
                        })
                    }

                }
            })
        });
    }

</script>
{/block}